package cn.com.nes.site.kafka;

import java.io.*;
import java.nio.charset.Charset;
import java.util.Properties;

public class JavaKafkaConfigurer {

    private static Properties properties;

    public static boolean isEmpty(String str) {
       if (null == str) {
           return true;
       }
       if (0 == str.trim().length()) {
           return true;
       }

       return false;
    }

    public synchronized static Properties getKafkaProperties() {

        if (null != properties) {
            return properties;
        }

        InputStream in = null;
        //获取配置文件kafka.properties的内容
        Properties kafkaProperties = new Properties();
        try {
//            FileInputStream kafkaFile = new FileInputStream(
//                    new File(System.getProperty("user.dir")) + "/core_properties/kafka.properties");
//            in = new BufferedInputStream(kafkaFile);
            InputStream inputStream =  JavaKafkaConfigurer.class.getResourceAsStream("/kafka/kafka.properties");
            in = new BufferedInputStream(inputStream);
            // prop.load(in);//直接这么写，如果properties文件中有汉字，则汉字会乱码。因为未设置编码格式。
            kafkaProperties.load(new InputStreamReader(in, Charset.forName("UTF-8")));
        } catch (Exception e) {
            //没加载到文件，程序要考虑退出
            e.printStackTrace();
        }
        properties = kafkaProperties;
        return kafkaProperties;
    }


}
